USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Offers-Insert]    Script Date: [[20120714223935]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223935]]
-- Description:	Insert record into table [dbo].[Offers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Offers-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Offers-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Offers-Insert]
	/*@Offer_RowNumber int =Null OUTPUT , 
	@Offer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@TotalPrice float =Null  , 
	@IsForeEver nchar =0  , 
	@FromDate datetime =Null  , 
	@ToDate datetime =Null  , 
	@Offer_Notes varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Offers](/*[Offer_ID], [Product_ID], [Quantity], [MeasureUnit_ID], [TotalPrice], [IsForeEver], [FromDate], [ToDate], [Offer_Notes]*/)
	VALUES     (/*@Offer_ID, @Product_ID, @Quantity, @MeasureUnit_ID, @TotalPrice, @IsForeEver, @FromDate, @ToDate, @Offer_Notes*/)

	/*SELECT @Offer_RowNumber = [Offer_RowNumber]
    FROM [dbo].[Offers]
    WHERE  ( [Offer_ID] =@Offer_ID )
	AND  ( [Product_ID] =@Product_ID )
	AND  ( [Quantity] =@Quantity )
	AND  ( [MeasureUnit_ID] =@MeasureUnit_ID )
	AND  ( [TotalPrice] =@TotalPrice )
	AND  ( [IsForeEver] =@IsForeEver )
	AND  ( [FromDate] =@FromDate )
	AND  ( [ToDate] =@ToDate )
	AND  ( [Offer_Notes] =@Offer_Notes )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Offers-update]    Script Date: [[20120714223935]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223935]]
-- Description:	Update record in table [dbo].[Offers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Offers-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Offers-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Offers-update]
	/*@Offer_RowNumber int =Null OUTPUT , 
	@Offer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@TotalPrice float =Null  , 
	@IsForeEver nchar =0  , 
	@FromDate datetime =Null  , 
	@ToDate datetime =Null  , 
	@Offer_Notes varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Offers] SET 
		/*[Offer_ID] =@Offer_ID, 
		[Product_ID] =@Product_ID, 
		[Quantity] =@Quantity, 
		[MeasureUnit_ID] =@MeasureUnit_ID, 
		[TotalPrice] =@TotalPrice, 
		[IsForeEver] =@IsForeEver, 
		[FromDate] =@FromDate, 
		[ToDate] =@ToDate, 
		[Offer_Notes] =@Offer_Notes*/
		/*WHERE ([Offer_ID] = @Offer_ID)*/
	/**/

	/*SELECT @Offer_RowNumber = [Offer_RowNumber]
    FROM [dbo].[Offers]
	WHERE ([Offer_ID] = @Offer_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Offers-Insert-Update]    Script Date: [[20120714223935]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223935]]
-- Description:	Insert OR Update record into table [dbo].[Offers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Offers-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Offers-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Offers-Insert-Update]
	/*@Offer_RowNumber int =Null OUTPUT , 
	@Offer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@TotalPrice float =Null  , 
	@IsForeEver nchar =0  , 
	@FromDate datetime =Null  , 
	@ToDate datetime =Null  , 
	@Offer_Notes varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Offers] 
					/*WHERE ([Offer_ID] = @Offer_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Offers](/*[Offer_ID], [Product_ID], [Quantity], [MeasureUnit_ID], [TotalPrice], [IsForeEver], [FromDate], [ToDate], [Offer_Notes]*/)
		VALUES     (/*@Offer_ID, @Product_ID, @Quantity, @MeasureUnit_ID, @TotalPrice, @IsForeEver, @FromDate, @ToDate, @Offer_Notes*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Offers] SET 
			/*[Offer_ID] =@Offer_ID, 
			[Product_ID] =@Product_ID, 
			[Quantity] =@Quantity, 
			[MeasureUnit_ID] =@MeasureUnit_ID, 
			[TotalPrice] =@TotalPrice, 
			[IsForeEver] =@IsForeEver, 
			[FromDate] =@FromDate, 
			[ToDate] =@ToDate, 
			[Offer_Notes] =@Offer_Notes*/
			/*WHERE ([Offer_ID] = @Offer_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Offer_RowNumber = [Offer_RowNumber]
    FROM [dbo].[Offers]
	WHERE ([Offer_ID] = @Offer_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Offers-Delete]    Script Date: [[20120714223935]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223935]]
-- Description:	delete records from table [dbo].[Offers] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Offers-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Offers-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Offers-Delete]
	/*@Offer_RowNumber int =null  , 
	@Offer_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Quantity float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@TotalPrice float =null  , 
	@IsForeEver nchar =null  , 
	@FromDate datetime =null  , 
	@ToDate datetime =null  , 
	@Offer_Notes varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Offers]
	WHERE /*( [Offer_RowNumber] = ISNULL(@Offer_RowNumber, [Offer_RowNumber]) )
	AND ( [Offer_ID] = ISNULL(@Offer_ID, [Offer_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Quantity] = ISNULL(@Quantity, [Quantity]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [TotalPrice] = ISNULL(@TotalPrice, [TotalPrice]) )
	AND ( [IsForeEver] = ISNULL(@IsForeEver, [IsForeEver]) )
	AND ( [FromDate] = ISNULL(@FromDate, [FromDate]) )
	AND ( [ToDate] = ISNULL(@ToDate, [ToDate]) )
	AND ( [Offer_Notes] like ISNULL(@Offer_Notes, [Offer_Notes]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Offers-Select]    Script Date: [[20120714223935]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223935]]
-- Description:	select records from table [dbo].[Offers] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Offers-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Offers-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Offers-Select]
	/*@Offer_RowNumber int =null  , 
	@Offer_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Quantity float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@TotalPrice float =null  , 
	@IsForeEver nchar =null  , 
	@FromDate datetime =null  , 
	@ToDate datetime =null  , 
	@Offer_Notes varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Offers]
	WHERE /*( [Offer_RowNumber] = ISNULL(@Offer_RowNumber, [Offer_RowNumber]) )
	AND ( [Offer_ID] = ISNULL(@Offer_ID, [Offer_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Quantity] = ISNULL(@Quantity, [Quantity]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [TotalPrice] = ISNULL(@TotalPrice, [TotalPrice]) )
	AND ( [IsForeEver] = ISNULL(@IsForeEver, [IsForeEver]) )
	AND ( [FromDate] = ISNULL(@FromDate, [FromDate]) )
	AND ( [ToDate] = ISNULL(@ToDate, [ToDate]) )
	AND ( [Offer_Notes] like ISNULL(@Offer_Notes, [Offer_Notes]) )*/
END
GO
-- =============================================
